/**
 * @param {string} s
 * @param {number} k
 * @return {string}
 */
 var digitSum = function(s, k) {
  let arr = String(s).split('').map(v => +v)
  while(arr.length > k) {
    let i = 0, next = []
    for(; i+k<arr.length; i+=k) {
      let c = 0
      for(let j = i; j<i+k; j++){
        c += arr[j]
      }
      next.push(c)
    }
    let last = 0
    for(; i<arr.length; i++) {
      last += arr[i]
    }
    next.push(last)
    arr = next.join('').split('').map(v => +v)
  }
  return arr.join('')
};